<template>
	<view class="allpayment">
		<!-- #ifdef APP-PLUS -->
		<Hearder :name="'设置微信'" v-if="type==0"></Hearder>
		<Hearder :name="'设置支付宝'" v-if="type==1"></Hearder>
		<Hearder :name="'设置银行卡'" v-if="type==2"></Hearder>
		<!-- #endif -->
		<view class="rzinfo">
			<view class="list">
				<view class="lable">姓名</view>
				<view class="right">
					<input placeholder="请输入您的姓名" placeholder-style="color:#999;" v-model="user_name">
				</view>
			</view>
			<view class="list" v-if="type==0">
				<view class="lable">微信号</view>
				<view class="right">
					<input placeholder="请输入您的微信账号" placeholder-style="color:#999;" v-model="card">
				</view>
			</view>
			<view class="list" v-if="type==1">
				<view class="lable">支付宝号</view>
				<view class="right">
					<input placeholder="请输入您的支付宝账号" placeholder-style="color:#999;" v-model="card">
				</view>
			</view>
			<view class="list" v-if="type!=2">
				<view class="lable">联系方式</view>
				<view class="right">
					<input placeholder="请填写手机号" placeholder-style="color:#999;" v-model="mobile">
				</view>
			</view>
			<view class="list" v-if="type!=2"  @click="uploadload">
				<view class="lable" v-if="type==0">微信收款码</view>
				<view class="lable" v-if="type==1">支付宝收款码</view>
				<view class="right" style="justify-content: flex-end;">
					<input :placeholder="type==0?'上传微信收款码':'上传支付宝收款码'" placeholder-style="color:#D00606;" disabled 
					style="text-align: right;margin-right: 20rpx;" v-if="!receive_image">
					<image :src="receive_image" v-else></image>
					<u-icon name="arrow-right" color="#999" size="18"></u-icon>
				</view>
			</view>
			<view class="list" v-if="type==2">
				<view class="lable">卡号</view>
				<view class="right">
					<input placeholder="请输入您的银行卡号" placeholder-style="color:#999;" v-model="bank_card">
				</view>
			</view>
			<view class="list" v-if="type==2">
				<view class="lable">银行</view>
				<view class="right">
					<input placeholder="请填写开户行银行" placeholder-style="color:#999;" v-model="opening_bank">
				</view>
			</view>
			<view class="list" v-if="type==2">
				<view class="lable">手机</view>
				<view class="right">
					<input placeholder="请联系手机号" placeholder-style="color:#999;" v-model="mobile">
				</view>
			</view>
			<view class="list" v-if="type==2">
				<view class="lable">开户省市</view>
				<view class="right">
					<input placeholder="填写开户省市（如广东省深圳市）" placeholder-style="color:#999;" v-model="opening_province_city">
					<u-icon name="arrow-right" color="#999" size="18"></u-icon>
				</view>
			</view>
		</view>
		<view class="submit" @click="surebd">确认绑定</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				choosenum:0,
				type: 0, // 0微信 1支付宝  2银行卡
				user_name:'',
				showLogin:false,
				card:'',
				receive_image:'',
				opening_bank:'',
				bank_card:'',
				mobile:'',
				opening_province_city:'',
				withdrawal_setting_id:''
			}
		},
		onLoad(options) {
			this.type = options.type || this.$route.query.type
			if(this.type==0){
				uni.setNavigationBarTitle({
				　　title: '设置微信'
				})
			}else if(this.type==1){
				uni.setNavigationBarTitle({
				　　title: '设置支付宝'
				})
			}else if(this.type==2){
				uni.setNavigationBarTitle({
				　　title: '设置银行卡'
				})
			}
			this.withdrawal_setting_id = options.withdrawal_setting_id || this.$route.query.withdrawal_setting_id
			this.request('/member/setPay',{},'GET').then(res => {
				if(res.data.code==1){
					if(this.type==0){
						this.user_name = res.data.data.wx_name
						this.card = res.data.data.wx_account
						this.mobile = res.data.data.wx_phone
						this.receive_image = res.data.data.wx_image
					}else if(this.type==1){
						this.user_name = res.data.data.zfb_name
						this.card = res.data.data.zfb_account
						this.mobile = res.data.data.zfb_phone
						this.receive_image = res.data.data.zfb_image
					}else if(this.type==2){
						this.user_name = res.data.data.bank_name
						this.bank_card = res.data.data.bank_card
						this.opening_bank = res.data.data.bank
						this.mobile = res.data.data.bank_phone
						this.opening_province_city = res.data.data.bank_address
					}
				}	
			})
		},
		methods:{
			loginhidden(data){
				this.showLogin=data
			},
			uploadload(){
				var that=this
				uni.chooseImage({
				  count: 1,
				  sourceType: ['album'],
				  success:(res) => {
					uni.uploadFile({
						// #ifdef H5
						url:'/upload/image',
						// #endif
						// #ifndef H5
						url: that.$Config.url + '/upload/image',
						// #endif
						filePath: res.tempFilePaths[0],
						name: 'iFile',
						header:{
							token: uni.getStorageSync('TOKEN')
						},
						success: res => {
							this.receive_image = JSON.parse(res.data).data.file_path
						}
					})
				  }
				})
			},
			surebd(){
				if(this.type==0){
					var data ={
						wx_name:this.user_name,
						wx_account:this.card,
						wx_phone:this.mobile,
						wx_image:this.receive_image,
						type:Number(this.type)+1
					}
				}else if(this.type==1){
					var data ={
						zfb_name:this.user_name,
						zfb_account:this.card,
						zfb_phone:this.mobile,
						zfb_image:this.receive_image,
						type:Number(this.type)+1
					}
				}else if(this.type==2){
					var data ={
						bank_name:this.user_name,
						bank_card:this.bank_card,
						bank:this.opening_bank,
						bank_phone:this.mobile,
						bank_address:this.opening_province_city,
						type:Number(this.type)+1
					}
				}
				this.request('/member/setPay',data).then(res => {
					if(res.data.code==1){
						this.$tip(res.data.msg)
						setTimeout(()=>{
							uni.navigateBack()
						},500)
					}else{
						this.$tip(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.allpayment{
		.rzinfo{
			margin: 0 4%;
			.list{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 0;
				border-bottom: $uni-border-bottom;
				.lable{
					width: 25%;
					font-size: 28rpx;
				}
				.right{
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 75%;
					input{
						width: 100%;
						font-size: 28rpx;
					}
					image{
						width: 59rpx;
						height: 59rpx;
						margin-right: 20rpx;
					}
					.u-icon{
						top: 0;
					}
				}
			}
		}
		.submit{
			margin: 49rpx 3%;
			height: 80rpx;
			background: $uni-item-color;
			text-align: center;
			line-height: 80rpx;
			font-weight: 800;
			color: #fff;
		}
	}
</style>
